package hongcheng.code_generator.entity.config;

import java.io.File;
import java.io.IOException;

import hongcheng.code_generator.exception.CustomException;

/**
 * 	输出地址配置
 * */
public class OutputConfig {
	/**
	 * 	基础文件夹地址
	 * */
	private String baseDir;
	/**
	 * 	生成文件的类名及包名的相关配置
	 * */
	private ClassConfig classConfig;
	
	/**
	 * 	获取controller类的输出地址
	 * */
	public String getControllerOutputPath() {
		File file = new File(baseDir + "/" +  classConfig.getControllerClassName() + ".java");
		try {
			return file.getCanonicalPath();
		} catch (IOException e) {
			CustomException customException = new CustomException("获取controller类的输出地址出错");
			customException.addSuppressed(e);
			throw customException;
		}
	}
	
	/**
	 * 	获取Service类的输出地址
	 * */
	public String getServiceOutputPath() {
		File file = new File(baseDir + "/" +  classConfig.getServiceClassName() + ".java");
		try {
			return file.getCanonicalPath();
		} catch (IOException e) {
			CustomException customException = new CustomException("获取Service类的输出地址出错");
			customException.addSuppressed(e);
			throw customException;
		}
	}
	
	/**
	 * 	获取ServiceImpl类的输出地址
	 * */
	public String getServiceImplOutputPath() {
		File file = new File(baseDir + "/" + classConfig.getServiceClassName() + "Impl.java");
		try {
			return file.getCanonicalPath();
		} catch (IOException e) {
			CustomException customException = new CustomException("获取ServiceImpl类的输出地址出错");
			customException.addSuppressed(e);
			throw customException;
		}
	}
	
	/**
	 * 	获取Dao类的输出地址
	 * */
	public String getDaoOutputPath() {
		File file = new File(baseDir + "/" +  classConfig.getDaoClassName() + ".java");
		try {
			return file.getCanonicalPath();
		} catch (IOException e) {
			CustomException customException = new CustomException("获取Dao类的输出地址出错");
			customException.addSuppressed(e);
			throw customException;
		}
	}
	
	/**
	 * 	获取Entity类的输出地址
	 * */
	public String getEntityOutputPath() {
		File file = new File(baseDir + "/" +  classConfig.getEntityClassName() + ".java");
		try {
			return file.getCanonicalPath();
		} catch (IOException e) {
			CustomException customException = new CustomException("获取Entity类的输出地址出错");
			customException.addSuppressed(e);
			throw customException;
		}
	}
	
	/**
	 * 	获取QueryVO类的输出地址
	 * */
	public String getQueryVOOutputPath() {
		File file = new File(baseDir + "/" +  classConfig.getVoClassName() + ".java");
		try {
			return file.getCanonicalPath();
		} catch (IOException e) {
			CustomException customException = new CustomException("获取QueryVO类的输出地址出错");
			customException.addSuppressed(e);
			throw customException;
		}
	}
	
	/**
	 * 	获取MapperXML文件的输出地址
	 * */
	public String getMapperXMLOutputPath() {
		File file = new File(baseDir + "/" +  classConfig.getMapperXMLFileName()+ ".xml");
		try {
			return file.getCanonicalPath();
		} catch (IOException e) {
			CustomException customException = new CustomException("获取MapperXML类的输出地址出错");
			customException.addSuppressed(e);
			throw customException;
		}
	}
	
	public OutputConfig() {
		super();
	}


	public OutputConfig(String baseDir, ClassConfig classConfig) {
		super();
		this.baseDir = baseDir;
		this.classConfig = classConfig;
	}
	
	
	public String getBaseDir() {
		return baseDir;
	}
	public void setBaseDir(String baseDir) {
		this.baseDir = baseDir;
	}

	public void setClassConfig(ClassConfig classConfig) {
		this.classConfig = classConfig;
	}
	
	
	
}
